package com.xiangban.test_xiangban.controller;

import com.xiangban.test_xiangban.domain.Parameter;
import com.xiangban.test_xiangban.domain.Test;

import com.xiangban.test_xiangban.domain.vo.ParameterVo;
import com.xiangban.test_xiangban.mapper.TestMapper;
import com.xiangban.test_xiangban.service.TestService;
import com.xiangban.test_xiangban.utils.JsonData;
import freemarker.template.TemplateException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jxl.read.biff.BiffException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/v1/test")
@Api(tags = "实操卷打印")
//@CrossOrigin(origins = "*", methods = {RequestMethod.GET, RequestMethod.POST})
//@CrossOrigin(origins = "*",maxAge = 3600)
public class TestController {

    @Autowired
    private TestService testService;

    @PostMapping("/importExcel")
    @ApiOperation("导入文件")
    public JsonData importExcel(@RequestParam("file") MultipartFile file) throws IOException, TemplateException, BiffException {
        String url = testService.importExcel(file);

        return JsonData.buildSuccess(url);
    }


    @PostMapping("/exportTest")
    @ApiOperation("导出试卷")
    public JsonData exportTest(@RequestBody ParameterVo parameterVo) throws IOException, TemplateException, BiffException {
        return testService.exportTest(parameterVo);
    }

    @GetMapping("/getSubject")
    @ApiOperation("获取题目")
    public JsonData getSubject(){
        List<Test> subject = testService.getSubject();
        return JsonData.buildSuccess(subject);
    }










}
